<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="com.listview.dao.ItemsDAO"%>
<%@ page import="com.listview.entity.Items"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>MyJSP 'details.jsp' starting page</title>
<meta content="no-cache" http-equiv="pragme">
<meta content="no-cache" http-equiv="cache-control">
<meta content="0" http-equiv="expires">
<meta content="jsp" http-equiv="keywords">
<meta content="This is my jsp page!" http-equiv="description">
<style type="text/css">
div {
	float: left;
	margin-left: 30px;
	margin-right: 30px;
	margin-top: 5px;
	margin-bottom: 5px;
}

div dd {
	margin: 0px;
	float-size: 10pt;
}

div dd.dd_name {
	color: blue;
}

div dd.dd_city {
	color: #000;
}
</style>
</head>
<body>
	<h1>商品详情</h1>
	<hr>

	<center>
		<table width="750" height="60" cellpadding="0" border="0">
			<tr>
				<!-- 商品详情 -->
				<%
					ItemsDAO itemDao = new ItemsDAO();
					Items item = itemDao.getItemsById(Integer.parseInt(request.getParameter("id")));
					if (item != null) {
				%>
				<td width="70%" valign="top">
					<table>
						<tr>
							<td rowspan="4"><img src="images/<%=item.getPicture()%>"
								width="200" height="160" /></td>
						</tr>
						<tr>
							<td><B><%=item.getName()%></B></td>
						</tr>
						<tr>
							<td>产地：<%=item.getCity()%></td>
						</tr>
						<tr>
							<td>价格：￥<%=item.getPrice()%></td>
						</tr>
					</table>
				</td>
				<%
					}
				%>
				<%
					String list = "";
					//从客户端获取Cookie集合
					Cookie[] cookies = request.getCookies();
					for (Cookie c : cookies) {
						if (c.getName().equals("ListViewCookie")) {
							list = c.getValue();
						}
					}
					list += request.getParameter("id") + ",";
					//浏览记录超过1k条，则清零
					String[] arr = list.split(",");
					if (arr != null && arr.length > 0) {
						if (arr.length >= 1000) {
							list = "";
						}
					}
					Cookie cookie = new Cookie("ListViewCookie", list);
					response.addCookie(cookie);
				%>
				<!-- 浏览过的商品 -->
				<td width="30%" bgcolor="#EEE" align="center"><br> <b>您浏览过的商品</b><br>
					<!-- 开始循环 --> <%
 	ArrayList<Items> itemsList = itemDao.getViewList(list);
 	if (itemsList != null && itemsList.size() > 0) {
 		for (Items i : itemsList) {
 %>
					<div>
						<dl>
							<dt>
								<a href="details.jsp?id=<%=i.getId()%>"><img
									src="images/<%=i.getPicture()%>" width="120" height="" /></a>
							</dt>
							<dd class="dd_name"><%=i.getName()%></dd>
							<dd class="dd_city">
								产地：<%=i.getCity()%></dd>
							<dd class="dd_city">
								价格：￥<%=i.getPrice()%></dd>
						</dl>
					</div> <!-- 循环结束 --> <%
 	}
 	}
 %></td>
			</tr>
		</table>
	</center>

</body>
</html>